import React, { Component } from 'react';
import { Redirect } from 'react-router-dom'
class Beforeeach extends Component {
	render() {
		const { component: Comp, auth, redirectAlreayLogin } = this.props

		if(auth && !localStorage.getItem('token')) {
			return <Redirect to="/login"></Redirect>
		}

		if(redirectAlreayLogin && localStorage.getItem('token')) {
			return <Redirect to="/"></Redirect>
		}

		return <Comp { ...this.props }></Comp>
	}
}

export default Beforeeach;
